<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>oak-apply-ri: openark kit documentation</title>
	<meta name="description" content="oak-apply-ri: openark kit" />
	<meta name="keywords" content="oak-apply-ri: openark kit" />
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
	<div id="main">
		<div id="header">
			<h1>openark kit documentation</h1>
			<div class="subtitle">Common utilities for MySQL</div>
		</div>
		<div id="contentwrapper">
			<div id="content">
				<h2><a href="oak-apply-ri.html">oak-apply-ri</a></h2>	
<h3>NAME</h3>
oak-apply-ri: apply referential integrity on two columns with parent-child  relationship.
<h3>SYNOPSIS</h3>
Delete rows from world.City where CountryCode does not have a matching Code in world.Country:
<blockquote>oak-apply-ri --parent=world.Country.Code --child=world.City.CountryCode --action=delete</blockquote>
Set CountryCode to NULL where no matching Code is found in world.Country:
<blockquote>oak-apply-ri --parent=world.Country.Code --child=world.City.CountryCode --action=setnull</blockquote>
Set CountryCode to NULL in chunks of 100, sleep 500 milliseconds between chunks:
<blockquote>oak-apply-ri --parent=world.Country.Code --child=world.City.CountryCode --action=setnull --chunk-size=100 --sleep=500</blockquote>
Same as above. Do not perform, just print the statements:
<blockquote>oak-apply-ri --parent=world.Country.Code --child=world.City.CountryCode -a setnull -c 100 --sleep=500 --print-only</blockquote>
Apply a normal safety level, which demands data types are identical:
<blockquote>oak-apply-ri --parent=world.Country.Code --child=world.City.CountryCode --action=setnull --safety-level=normal</blockquote>
Apply a high safety level, which demands column names and data types are identical:
<blockquote>oak-apply-ri --parent=world.Country.Code --child=world.City.CountryCode --action=setnull --safety-level=high</blockquote>
Provide connection parameters. Prompt for password:
<blockquote>oak-apply-ri --user=root --ask-pass --socket=/tmp/mysql.sock --parent=world.Country.Code --child=world.City.CountryCode --action=delete</blockquote>
Use a defaults file for parameters. Do not perform any safety checks:
<blockquote>oak-apply-ri --defaults-file=/home/myuser/.my-oak.cnf --parent=world.Country.Code --child=world.City.CountryCode --safety-level=none</blockquote>
<h3>DESCRIPTION</h3>
This tool can be used when you are not using Foreign Keys (either not using a storage engine with supports foreign keys, aush as InnoDB, or not using referencial integrity in your schema), but would like to ensure that Foreign Key contraints apply on your database. With this tool you may perform the following:
<ul>
	<li>Delete "orphaned" rows (as in ON DELETE CASCADE)</li>
	<li>Set "orphaned" rows reference to NULL (as in ON DELETE SET NULL)</li>
	<li>Print our whatever need to done without executing</li>
	<li>Evaluate if adding a Foreign Key contraint is possible</li>
</ul>
oak-apply-ri works with varying safety levels. Each safety level adds sanity checks to the previous one:
<ul>
	<li>None: does not perform checks</li>
	<li>Normal: validates that both columns are of the same data type</li>
	<li>High: validates that both columns have the same name.</li>
</ul>
Actual delete or update can be a lengthy operation, and may lock the child table. oak-apply-ri can work in specified chunk size, and with a configurable delay between chunk operations.

Integrity can be applied for columns of different schemas.
<h3>OPTIONS</h3>
-a ACTION, --action=ACTION
<p class="indent">Action to take on invalid (orphaned) rows. Can be either <span style="text-decoration: underline;">delete</span> or <span style="text-decoration: underline;">setnull.</span></p>
<p class="indent"><span style="text-decoration: underline;">delete</span> issues a DELETE on orphaned rows. <span style="text-decoration: underline;">setnull</span> issues an UPDATE on those rows, setting orphaned key to NULL.</p>
<p class="indent"><span style="text-decoration: underline;">setnull</span> is the default value. It is impossible to use 'setnull' for a NOT NULL child column.</p>

--ask-pass
<p class="indent">Prompt for password.</p>

--child=CHILD_COLUMN
<p class="indent">Fully qualified child (referencing) column. Must be in the following format: schema_name.table_name.column_name</p>

-c CHUNK_SIZE, --chunk-size=CHUNK_SIZE
<p class="indent">Number of values to act on in chunks. This does not map directly to number of rows, but rather to number of distinct orphaned values.</p>
<p class="indent">Default chunk size is 0, which means all rows are deleted/updated in one operation</p>

--defaults-file=DEFAULTS_FILE
<p class="indent">Read from MySQL configuration file. Overrides --user, --password, --socket, --port.</p>
<p class="indent">Configuration needs to be in the following format:</p>

<p class="indent"><strong>[client]<br/>
user=my_user<br/>
password=my_pass<br/>
socket=/tmp/mysql.sock<br/>
port=3306</strong>
</p>

-H HOST, --host=HOST
<p class="indent">MySQL host (default: localhost)</p>

-l SAFETY_LEVEL, --safety-level=SAFETY_LEVEL
<p class="indent">Level of tests to make in order for action to take place. Valid values are:</p>
<p class="indent"><span style="text-decoration: underline;">none</span>: no tests are performed</p>
<p class="indent"><span style="text-decoration: underline;">normal</span> (default): columns are tested to be of identical date type</p>
<p class="indent"><span style="text-decoration: underline;">high</span>: smae as 'normal' + columns are tested to be of identical names</p>

--parent=PARENT_COLUMN
<p class="indent">Fully qualified parent (referenced) column. Must be in the following format: schema_name.table_name.column_name</p>

-p PASSWORD, --password=PASSWORD
<p class="indent">MySQL password</p>

-P PORT, --port=PORT
<p class="indent">TCP/IP port (default: 3306)</p>

--print-only
<p class="indent">Do not execute. Only print statement</p>

--sleep=SLEEP_MILLIS
<p class="indent">Number of milliseconds to sleep between chunks. Default: 0</p>

-S SOCKET, --socket=SOCKET
<p class="indent">MySQL socket file. Only applies when host is localhost</p>

-u USER, --user=USER
<p class="indent">MySQL user</p>

-v, --verbose
<p class="indent">Print user friendly messages</p>

<h3>ENVIRONMENT</h3>
Requires MySQL 5.0 or newer, python 2.3 or newer.

python-mysqldb must be installed in order to use this tool. You can
<blockquote>apt-get install python-mysqldb</blockquote>
or
<blockquote>yum install mysql-python</blockquote>
<h3>SEE ALSO</h3>
<h3>LICENSE</h3>
This tool is released under the BSD license.
<blockquote><pre>Copyright (c) 2008 - 2010, Shlomi Noach
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre>
</blockquote>
<h3>AUTHOR</h3>
Shlomi Noach
				<br/>
			</div>
			<div id="sidebarwrapper">
				<div id="menu">
					<h3>openark kit tools</h3>
					<ul>
						<li><a title="Introduction" href="introduction.html">Introduction</a></li>
						<li><a title="Download" href="download.html">Download</a></li>
						<li><a title="Install" href="install.html">Install</a></li>
						<li><a title="oak-apply-ri" href="oak-apply-ri.html">oak-apply-ri</a></li>
						<li><a title="oak-block-account" href="oak-block-account.html">oak-block-account</a></li>
						<li><a title="oak-chunk-update" href="oak-chunk-update.html">oak-chunk-update</a></li>
						<li><a title="oak-get-slave-lag" href="oak-get-slave-lag.html">oak-get-slave-lag</a></li>
						<li><a title="oak-hook-general-log" href="oak-hook-general-log.html">oak-hook-general-log</a></li>
						<li><a title="oak-kill-slow-queries" href="oak-kill-slow-queries.html">oak-kill-slow-queries</a></li>
						<li><a title="oak-modify-charset" href="oak-modify-charset.html">oak-modify-charset</a></li>
						<li><a title="oak-online-alter-table" href="oak-online-alter-table.html">oak-online-alter-table</a></li>
						<li><a title="oak-prepare-shutdown" href="oak-prepare-shutdown.html">oak-prepare-shutdown</a></li>
						<li><a title="oak-purge-master-logs" href="oak-purge-master-logs.html">oak-purge-master-logs</a></li>
						<li><a title="oak-repeat-query" href="oak-repeat-query.html">oak-repeat-query</a></li>
						<li><a title="oak-security-audit" href="oak-security-audit.html">oak-security-audit</a></li>
						<li><a title="oak-show-limits" href="oak-show-limits.html">oak-show-limits</a></li>
						<li><a title="oak-show-replication-status" href="oak-show-replication-status.html">oak-show-replication-status</a></li>
					</ul>
				</div>
			</div>	
			<div class="clear">&nbsp;</div>
			
			<div id="footnote" align="center">
				<a href="">openark kit</a> documentation
			</div>
		</div>
	</div>
</body>
</html>
